<template>
    <div class="box">
        <div class="top">
            <h2>短信验证码登录/注册</h2>
            <p>新手机号将自动注册，请详读<span>豆瓣使用协议、豆瓣个人信息保护政策</span></p>
        </div>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="phone" label="手机号"
                    :rules="[{ pattern: pattern, required: true, message: '请输入11位手机号' }]" />

                <van-field v-model="sms" center clearable label="验证码"
                :rules="[{  required: true, message: '请输入6位验证码' }]">
                    <template #button>
                        <van-button size="small" type="primary" style="background: none;color: green;" @click="getsms">
                            获取验证码</van-button>
                    </template>
                </van-field>
                <div style="margin:">
                    <van-button block type="primary" native-type="submit">
                        登录
                    </van-button>
                </div>
            </van-cell-group>

        </van-form>





    </div>
</template>

<script setup>
import { ref } from 'vue';


let phone = ref('')
let pattern = /^1\d{10}$/
let sms = ref([])
let time = ref(0)

let getsms = () => {
    time.value = 6
    sms.value = Math.random().toString().slice(2, 8)

    let time1 = setInterval = (() => {
        time.value--
        console.log(time.value);

        if (time.value == 0) {
            clearInterval(time1)
        }
    }, 1000)
}
</script>

<style lang="scss" scoped>
.box {
    width: 100%;
    height: 100%;

    .top {
        width: 100%;
        text-align: center;
        margin-top: 3rem;

        p {
            margin-top: 1rem;

            span {
                color: green;

            }
        }

    }

    .van-cell-group {
        margin-top: 2rem;

    }

    .van-button {
        border-radius: none;
        background: green;
        color: white;
        border: none;
    }
}
</style>